<template>
    <div>
        <el-container>
            <el-main>
                <div class="studentList-info-title">
                    <p>
                        病人列表<el-button  size="large" type="primary" @click="patientDialogVisible=true">添加病人</el-button>
                    </p>
                </div>
                <div class="studentList-info-body">
                    <div class="studentList">
                        <el-table fixed :data="patientForm" stripe style="width: 100%" max-height="500">
                            <el-table-column type="index" :index="typeIndex" label="序号" align="center"></el-table-column>
                            <el-table-column prop="stuRealName" label="姓名" align="center"></el-table-column>
                            <el-table-column prop="sex" label="性别" align="center"></el-table-column>
                            <el-table-column prop="age" label="年龄" align="center"></el-table-column>
                            <el-table-column prop="phone" label="电话号码" align="center"></el-table-column>
                            <el-table-column prop="heart_status" label="心理状态" align="center"></el-table-column>
                            <el-table-column prop="timeString" label="时间" align="center"></el-table-column>
                            <el-table-column align="center" label="操作" fixed="right" width="200">

                                <el-button size="mini" type="primary" plain @click="modifyUser(scope.$index, scope.row)"
                                           style="background-color: #409EFF;border-color: #409EFF;color:#fff;">修改</el-button>
                                <el-button size="mini" type="primary" plain @click="deleteUser(scope.$index, scope.row)"
                                           style="background-color: #409EFF;border-color: #409EFF;color:#fff;">删除</el-button>

                            </el-table-column>
                        </el-table>
                    </div>
                    <!--<div class="studentList-pagination">-->
                    <!--<el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"-->
                    <!--:current-page="listQuery.current" :page-sizes="[10,20,30,50]" :page-size="listQuery.limit"-->
                    <!--:layout="paginationData" :total="total">-->
                    <!--</el-pagination>-->
                    <!--</div>-->
                </div>
                <div>
                    <el-dialog v-model="patientDialogVisible" title="添加病人" @close="closepage" width="650px"
                               :before-close="handleClose">

                        <el-form autoComplete="on" :model="addPatient" :rules="userRules" ref="addpatientForm" label-width="120px"
                                 label-position="right" class="card-box shop-form">
                            <el-form-item class="inp" prop="trueName" label="姓名：" style="width: 80%;">
                                <el-input name='stuRealName' v-model="addPatient.stuRealName" autoComplete="on" clearable />
                            </el-form-item>
                            <el-form-item class="inp" prop="age" label="年龄：" style="width: 80%;">
                                <el-input name='age' v-model="addPatient.age" autoComplete="on" clearable />
                            </el-form-item>
                            <el-form-item class="inp" prop="sex" label="性别：" style="width: 80%;">
                                <el-input name='sex' v-model="addPatient.sex" autoComplete="on" clearable />
                            </el-form-item>
                            <el-form-item class="inp" prop="phone" label="电话号码：" style="width: 80%;">
                                <el-input name='phone' v-model="addPatient.phone" autoComplete="on" clearable />
                            </el-form-item>
                            <el-form-item class="inp" prop="heart_status" label="心里状态：" style="width: 80%;">
                                <el-input name='heart' v-model="addPatient.heart" autoComplete="on" clearable />
                            </el-form-item>
                            <el-form-item class="inp" prop="timeString" label="日期：" style="width: 80%;">
                                <el-select v-model="addPatient.Time.Time">
                                    <el-option
                                            v-for="item in timeDict_Time"
                                            :label="item"
                                            :value="item"
                                            :key="item">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <div class="studentList-btn">
                                <el-button class="formBtn" :loading="loading" @click="handleComplaint()">
                                    提交
                                </el-button>
                                <el-button class="formBtn" :loading="loading" @click="handleCancel()">
                                    取消
                                </el-button>
                            </div>
                        </el-form>

                    </el-dialog>
                </div>
            </el-main>
        </el-container>
    </div>
</template>

<script>
     import request from "../../utils/request";
    // import {submitConsultant, deleteConsultant,patientData} from "../../api/patientPage";
    // import {getConsultants} from "vue/src/api/user/index.js"

    export default {
        data(){
            return{
                patientDialogVisible: false,
                listLoading: false,
                exportFile: {
                    text: ''
                },
                exportForm: {
                    file: ''
                },
                patientForm: [{
                    stuRealName:'王志华',
                    sex:'男',
                    age:'18',
                    heart_status:'抑郁',
                    phone:'123',
                    timeString:'',
                }],
                addPatient:{
                    stuRealName:'',
                    sex: '',
                    age: '',
                    phone:'',
                    heart:'',
                    Time: {
                        Week: [{}],
                        Time: [{}]
                    }
                },
                timeDict_Week:[],
                timeDict_Time:[],
                loading: false,
                list: [],
                messageForm: {
                    userName: '',
                    userId: '',
                    messageType: '0',
                    messageContent: ''
                },
                userRules: {
                    stuRealName: [{
                        required: true,
                        message: '姓名不能为空',
                        trigger: 'blur'
                    }],
                    phone: [{
                        required: true,
                        message: '电话不能为空',
                        trigger: 'blur'
                    }],
                    age: [{
                        required: true,
                        message: '年龄不能为空',
                        trigger: 'blur'
                    }],
                    sex: [{
                        required: true,
                        message: '性别不能为空',
                        trigger: 'blur'
                    }]
                },

                paginationData: 'total, sizes, prev, pager, next, jumper',
                total: null,


                //分页大小
                listQuery: {
                    current: 1,
                    size: 10,
                    condition: {}
                },
            }
        },

        methods: {

            handleClose(done) {
                this.$confirm('确认关闭？')
                    .then(_ => {
                        done();
                    })
                    .catch(_ => {});
            },

            typeIndex(index) {
                return index + (this.listQuery.current - 1) * this.listQuery.size + 1
            },

            // getConsultants(){
            //     return request({
            //         url: '/api/user/consultants',
            //         method: 'get'
            //     })
            // },
            //获取数据
            getData(){
                this.getConsultants().then(res => {
                    if(res.code ===1) {
                        this.patientForm = res.data;
                        console.log(res.data)
                    }
                })
            },

            //添加
            async handleSubmit(){
                this.patientDialogVisible = false
                await console.log(this.addLog)
                this.submitConsultant(this.addLog).then(res=>{
                    if(res.code === 1){
                        console.log(res)
                        this.getData()
                    } else {
                        ElMessage.error(res.message);
                    }
                })
                console.log('提交')
            },


            //取消添加
            handleCancel() {
                this.$nextTick(() => {
                    this.$refs['addpatientForm'].resetFields()
                })
                this.patientDialogVisible = false
            },

            //回调
            closepage() {
                this.$nextTick(() => {
                    this.$refs['addpatientForm'].resetFields()
                })
            },

            //分页
            handleSizeChange(val) {
                this.listQuery.size = val
                this.getData()
            },
            handleCurrentChange(val) {
                this.listQuery.current = val
                this.getData()
            },

            //修改
            modifyUser(index, row) {
                this.patientForm = row
                this.addFlag = false
                this.patientDialogVisible = true
            },

            //删除
            deleteUser(index, row) {
                this.$confirm('删除后不可恢复，确定删除？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.deleteConsultant({
                        'id': row.id
                    }).then(resp => {
                        if (resp.code == 200) {
                            this.$message({
                                type: 'success',
                                message: "删除成功！"
                            })
                            this.getData()
                        } else {
                            this.$message({
                                type: 'error',
                                message: "系统错误！"
                            })
                        }
                    })
                })
            }
        },
        created() {
            // this.getData()
        }
    }
</script>

<style scoped>
    .studentList-info-title {
        width: auto;
        height: 56px;
        background-color: #EDEFF2;
        font-size: 22px;
        /* font-family: SimHei; */
        font-weight: 400;
        color: #333333;
        line-height: 48px;
        border-left: 6px solid #409EFF;
        text-align: left;
    }

    .studentList-info-title p {
        padding-left: 25px;
        padding-top: 5px;
    }

    .addUserBtn {
        width: 140px;
        height: 44px;
        color: #ffffff;
        background-color: #409EFF;
        float: right;
        margin-right: 70px;
    }

    .studentList-btn {
        text-align: center;
    }

    .studentList-btn .formBtn {
        width: 120px;
        height: 44px;
        background-color: #409EFF;
        border-color: #409EFF;
        color: #ffffff;
    }

    .studentList-pagination {
        margin-top: 50px;
        text-align: center;
        padding-bottom: 50px;
    }

    .el-pagination.is-background .el-pager li.active {
        background-color: #409EFF;
    }

</style>